package com.wolf.client;

import com.wolf.core.Protocol;
import com.wolf.core.ResponseEntity;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.concurrent.Promise;

/**
 * @auth: dylan
 * @Desc:
 * @Time: 2024/5/1
 */
public class ClientInboundHandler extends SimpleChannelInboundHandler<Protocol<ResponseEntity>> {
    @Override
    protected void channelRead0(ChannelHandlerContext context, Protocol<ResponseEntity> protocol) throws Exception {
        //把结果设置到异步结果中
        long serialId = protocol.getHeader().getSerialId();
        Object result = protocol.getContent().getData();
        Promise promise = Holder.REQ_RESULT_MAP.get(serialId);
        promise.setSuccess(result);
        context.channel().closeFuture();
    }
}
